Skip to content

Image entity: re-fetch until the AP has stored the new image - #365

Closed
r1ch wants to merge 1 commit into
OpenEPaperLink:mainfrom
r1ch:fix-image-refresh-race
Closed

r1ch wants to merge 1 commit into
OpenEPaperLink:mainfrom
r1ch:fix-image-refresh-race

Conversation

@r1ch

@r1ch r1ch commented Nov 19, 2026

Copy link
Copy Markdown

Problem

After a successful drawcustom to an AP tag, the image.*_content entity often keeps showing the previous picture until HA restarts or the integration is reloaded.

The coordinator fires SIGNAL_TAG_IMAGE_UPDATE when the AP logs reports xfer complete, and the image entity immediately fetches /current/<mac>.raw. The AP logs that message just before the new image is in place, so the fetch can return the old file. Seen here: the AP's updatelast was 06:45:20, HA refreshed at 06:45:21 and decoded the previous day's image, while the tag and the AP's /current/<mac>.raw (fetched a few minutes later) had the new one.

Fix

On the xfer-complete signal, ESLImage now re-fetches with backoff (1, 2, 4, 8, 15 s) until the raw file differs from the one it last fetched, then decodes it. If it never changes (the same picture was sent again), it uses the last fetch. A pending re-fetch is cancelled by a newer transfer or when the entity is removed. Dry-run previews (bytes signal) are unchanged and don't affect the comparison.

Only image.py changes; independent of #363.

Testing

Running locally against an AP with BWRY 2.9" tags. Reloading the integration afterwards showed the correct new image, confirming the AP file was already updated shortly after the event.

🤖 Generated with Claude Code

The AP logs 'reports xfer complete' before the new image is moved into
/current/<mac>.raw, so the immediate fetch could return the previous image
and the image entity stayed one picture behind until the next restart.
After a transfer, re-fetch with backoff (1-15 s) until the file differs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@r1ch r1ch mentioned this pull request Nov 21, 2026
@g4bri3lDev

Copy link
Copy Markdown
Member

Thanks for tracking this down! 3.x is being replaced by the 4.0 rewrite in #362, so I'm closing this. 4.0 refreshes the image when the tag's hash changes, which only happens after the AP has stored the file, so it doesn't have this race. Details in #362.

@g4bri3lDev g4bri3lDev closed this Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants